Skip to main content

Set file metadata through a rule

Overview

Setting the metadata for a file refers to filling out information fields whenever you integrate your corporate ECM document repository. This section presents an alternative for filling out metadata, compared to the one presented in Setting the ECM in Bizagi.

Filling Out Metadata

By default, a document uploaded through the ECM control allows users to manually edit this information. However, when using ECM integration, there are scenarios in which you may want to automatically map business information into a document to be stored at the ECM.

This means that you may choose to use a business rule to set information from the case into the repository's folder metadata.

The examples below illustrate methods to use in a rule that automatically maps information into the uploaded document.


Example 1

In this example, we map information already contained in our case into the Title and Description metadata. Our ECM file upload is set in MyProcessEntity.MyFileAttribute.

var xPath = "MyProcessEntity.MyFileAttribute"; // This XPath corresponds to the data model's file attribute
var metadataHash = new Hashtable(); // This creates a temporary structure to hold metadata

metadataHash.Add("Title", <MyProcessEntity.CustomerNameAttribute>);
metadataHash.Add("Description", <MyProcessEntity.SomeDescriptionAttribute>);

// Do this to set each metadata field

var tmpFileAttribute = Me.getXPath(xPath); // This obtains all information in the file attribute
for (var i = 0; i < tmpFileAttribute.size(); i++) { // Iteration is done, as this file could contain more than 1 document

var tmpFile = tmpFileAttribute.get(i); // This obtains the actual document
var idFileUpload = tmpFile.getXPath("id"); // This obtains the id for the actual document
var completeXpath = xPath + "[id=" + idFileUpload + "]"; // This builds the complete XPath to reference each document

CHelper.UpdateECMMetadata(Me, metadataHash, completeXpath); // Method to map metadata
}

Example 2

In this example, our rule is set outside of a table, but we will map metadata for all uploads inside a table. This means that we map Title and Description metadata (information already contained in our case) for an ECM file upload contained in MyProcessEntity.MyCollection.MyFileAttribute (as a column of a table).


var xPath = "MyFileAttribute"; // This XPath corresponds to the data model's file attribute
var xPathContext = "MyProcessEntity.MyCollection"; // This XPath corresponds to the context of the actual table
var metadataHash = new Hashtable(); // This creates a temporary structure to hold metadata

metadataHash.Add("Title", <MyProcessEntity.CustomerNameAttribute>);
metadataHash.Add("Description", <MyProcessEntity.SomeDescriptionAttribute>);

var List = Me.getXPath(xPathContext); // This obtains the information in the table
var Array = CHelper.GetValueAsCollection(List);

for (var j = 0; j < Array.size(); j++) { // Iteration is done for the records of that table
var tmpRecord = Array.get(j); // This obtains the actual record
var FileAttrib = tmpRecord.getXPath(xPath); // This obtains all information in the file attribute
var idRecord = tmpRecord.getXPath("id"); // This obtains the id for the actual record

for (var i = 0; i < FileAttrib.size(); i++) { // Iteration is done, as this file could contain more than 1 document

var SubFile = FileAttrib.get(i); // This obtains the actual document of that record
var idFileUpload = SubFile.getXPath("id"); // This obtains the id for the actual document
var completeXpath = xPathContext + "[id=" + idRecord + "]." + xPath + "[id=" + idFileUpload + "]"; // This builds the complete XPath to reference each document

CHelper.UpdateECMMetadata(Me, metadataHash, completeXpath); // Method to map metadata
}
}